package cn.e3mall.item.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.e3mall.common.utils.E3Result;
import cn.e3mall.item.pojo.Item;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.pojo.TbItemDesc;
import cn.e3mall.service.ItemService;

/**
 * @author jiangbin
 * @version 1.0.0
 * @description 商品详情页面展示的controller
 */
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/item/{itemId}")
    public String showItem(@PathVariable Long itemId, Model model){
        //1.获取商品基本信息
        E3Result e3Result = itemService.getItemById(itemId);
         TbItem tbItem = (TbItem)e3Result.getData();
        Item item = new Item(tbItem);
        //2.获取商品描述信息
        TbItemDesc tbItemDesc = (TbItemDesc) itemService.getItemDescById(itemId).getData();
        //3.返回页面需要的对象
        model.addAttribute("item",item);
        model.addAttribute("itemDesc",tbItemDesc);
        //4.返回逻辑视图
        return  "item";
    }
}
